package com.xiaoma.tpo.dao;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.tpo.domain.WdWord;

@Repository
public class WdWordDao extends BaseDaoImpl<WdWord>{

    private static final Logger LOG = LoggerFactory.getLogger(WdWordDao.class);
    
    @SuppressWarnings("unchecked")
    public List<WdWord> findByGroupId(int groupId){
        String sql = "SELECT * FROM wd_word WHERE id in (SELECT wd_word_id FROM wd_group_word where wd_group_id = ?)";
        LOG.info("SQL:{} PARAMS:{}", sql, groupId);
        List<?> reslut = jdbcTemplate.query(sql, new DefaultRowMapper(WdWord.class, getNameHandler()), groupId);
        return (List<WdWord>)reslut;
    }
    
    public int findWordCountByGroupId(int groupId) {
        String sql = "SELECT count(1) FROM wd_group_word WHERE wd_group_id = ?";
        LOG.info("SQL:{}", sql, groupId);
        return jdbcTemplate.queryForInt(sql, groupId);
    }
}
